home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / I-Z / Xlisp_Source.cpt / Step10.LSP < prev    next >
Lisp/Scheme  |  1985-04-27  |  9KB  |  247 lines

  1. ;+
  2. ;               STEP 1.0 : (C) Copyright 1985 by Gregory Frascadore
  3. ;
  4. ;   This software may be copied, distributed to others, and modified as long
  5. ;   as it is not sold for profit, and as long as this copyright notice is
  6. ;   retained intact. For further information regarding STEP, contact the 
  7. ;   author at:
  8. ;               frascado%umn-cs.CSNET   (on CSNET)
  9. ;               75106,662               (on CompuServe)
  10. ;-
  11.  
  12. ;+
  13. ;                               STEP 1.0
  14. ; DESCRIPTION
  15. ;   STEP is an interactive debugging tool for use with XLISP 1.4 . With 
  16. ;   modification, STEP may work with later versions of XLISP or with other
  17. ;   lisp systems.
  18. ;
  19. ; UPDATE HISTORY
  20. ;   Version 1.0 - Original version, March 1985 by Gregory Frascadore.
  21. ;-
  22.  
  23. ;+
  24. ; Here is where the global symbols are given values. Global symbols are
  25. ; distinguished from other symbols by their starting and ending asterisks.
  26. ; ie *global* . Function parameters start with an asterisk, but do not end
  27. ; with one ie *foo. Local symbols (like those in do, and let) end in asterisks
  28. ; ie bar*
  29. ;-  
  30. (setq *step-inprompt* '?            ; Each instep is identified by leading '?'
  31.       *step-outprompt* '=           ; Outsteps have leading '='
  32.       *step-count* 0                ; How many steps to make without prompting.
  33.       *step-indent* 0               ; The initial amount of indentation.
  34.       *step-indent-incr* 2          ; How much more to indent at each new level
  35.       *step-keys* nil               ; List of breakpoint atoms
  36.       *step-transparent* t          ; Flag, determines when to print to user.
  37.       *evalhookfnc* '(lambda (*sexpr) (eval *sexpr)) )
  38.                                     ; The initial evalhook is a nop function.
  39.  
  40. ;+
  41. ; step
  42. ;   Turns on stepping or sets breakpoints.
  43. ;   
  44. ; format
  45. ;   (step [<atom>]...)  -if no atoms are specified, stepping begin immediately.
  46. ;-       
  47. (defun step (&rest *keys)
  48.  
  49.     (if *keys                        
  50.         (setq *step-keys* *keys     
  51.               *step-transparent* t )
  52.         (setq *step-transparent* nil) )
  53.  
  54.     (setq *step-count* 0                            
  55.           *step-indent* 0 )
  56.  
  57.     (rplacd *evalhookfnc* (cdr stepper))    ; Set stepper as evalhookfnc
  58.     (setq *evalhook* *evalhookfnc*) t)      ; then start intercepting evals.
  59.  
  60. ;+
  61. ; nostep
  62. ;   Turns off stepping.
  63. ;
  64. ; format
  65. ;   (nostep)
  66. ;       returns t always
  67. ;-
  68. (defun nostep ()
  69.     (rplacd *evalhookfnc* '((*sexpr) (eval *sexpr))) t)
  70.  
  71.  
  72. (defun stepper (*sexpr)
  73.  
  74. ; If the car of the expression being evaluated is in the breakpoint list
  75. ; then take the stepper out of transparent mode.
  76.  
  77.     (if (and (consp *sexpr)
  78.              (member (car *sexpr) *step-keys*) )
  79.                      (setq *step-transparent* nil))
  80.  
  81. ; Start indenting at a deeper level. If the indent is in some weird state
  82. ; restore it to a level 1 indent ie 0 + incr.
  83.  
  84.     (if (<= *step-indent* 0)
  85.             (setq *step-indent* *step-indent-incr*)
  86.             (setq *step-indent* (+ *step-indent-incr* *step-indent*)) )
  87.  
  88. ; Eval the current *sexpr. If we are at level 1, set a catch we can throw
  89. ; to from deeper levels. Otherwise just do a simple step-evel. When completing
  90. ; a level 1 eval, turn off transparency and restore the evalhookfnc if they
  91. ; were disabled from a deeper level.
  92.  
  93.     (prog1
  94.         (cond ((eql *step-indent* *step-indent-incr*)
  95.                 (prog1
  96.                     (catch '*step-toplevel* (step-eval *sexpr))
  97.                     (setq *step-count* 0)
  98.                     (cond ((eql *step-transparent* 'c) 
  99.                                 (setq *step-transparent* nil)
  100.                                 (rplacd *evalhookfnc* (cdr stepper)) ) ) ) )
  101.  
  102.               (t (step-eval *sexpr)) )
  103.         (setq *step-indent* (- *step-indent* *step-indent-incr*)) ) )
  104.  
  105.  
  106. (defun step-eval (*sexpr)
  107.  
  108. ; Eval the current *sexpr. If *step-count* is greater than 0, do not prompt
  109. ; the user for instructions, but do continue to produce output if not in
  110. ; transparent mode.
  111.  
  112.     (cond ((zerop *step-count*)
  113.             (if (not *step-transparent*)
  114.                 (prog2
  115.                     (step-prompt *step-inprompt* *sexpr)
  116.                     (step-prompt *step-outprompt* (step-docmd *sexpr))
  117.                     (terpri) )
  118.                 (evalhook *sexpr stepper nil) ) )
  119.  
  120.           ((> *step-count* 0)
  121.             (setq *step-count* (1- *step-count*))
  122.             (if (not *step-transparent*)
  123.                 (prog2
  124.                     (progn 
  125.                         (step-prompt *step-inprompt* *sexpr)(terpri))
  126.                         (step-prompt *step-outprompt* 
  127.                                      (evalhook *sexpr stepper nil))(terpri) )
  128.                     (evalhook *sexpr stepper nil) ) )
  129.  
  130.           (t (break "%Error, Stepper loses")) ) )
  131.  
  132.  
  133.  
  134. (defun step-docmd (*sexpr)
  135.  
  136. ; If the *sexpr is an atom, don't bother asking the user what to do. Just echo
  137. ; the atom and its value. If its not an atom, ask the user what to do until
  138. ; he gives you a legal responce that either continues or aborts the evaluation.
  139.  
  140.     (do* (cmd*  (value* (cond ((atom *sexpr) (terpri) (eval *sexpr))
  141.                             (t '*unbound*) )))
  142.          ((cond ((boundp 'value*) t)
  143.                 (t (setq cmd* (step-getcmd)) nil) )
  144.                     value*)
  145.  
  146.             (case cmd*
  147.  
  148.             '(?     (step-help))
  149.  
  150.             '(+     (let ((key* (read)))
  151.                                 (if (atom key*)
  152.                                          (setq *step-keys* 
  153.                                                (cons key* *step-keys*) ) 
  154.                                          (step-huh?) ) ))
  155.  
  156.             '(-     (let ((key* (read)))
  157.                                 (if (atom key*)
  158.                                          (setq *step-keys*
  159.                                                (remove key* *step-keys*) )
  160.                                          (step-huh?) ) ))
  161.  
  162.             '(b     (break "STEP BREAK, type 'continue' or 'quit' when done"))
  163.  
  164.             '(c     (setq *step-transparent* 'c)
  165.                       (setq value* (evalhook *sexpr stepper nil)) )
  166.  
  167.             '(e     (throw '*step-toplevel* t))
  168.  
  169.             '(g     (rplacd *evalhookfnc* '((*sexpr) (eval *sexpr)))
  170.                       (setq *step-transparent* 'c)
  171.                       (setq value* (eval *sexpr)) )
  172.  
  173.             '(h     (step-help))
  174.  
  175.             '(n     (setq value* (eval *sexpr)))
  176.  
  177.             '(q     (setq *step-keys* nil)
  178.                       (rplacd *evalhookfnc* '((*sexpr) (eval *sexpr)))
  179.                       (throw '*step-toplevel* t) )
  180.  
  181.             '(s    (setq value* (evalhook *sexpr stepper nil)))
  182.                            
  183.             '(x     (throw '*step-toplevel* t) )
  184.  
  185.             '(t     (cond ((numberp cmd*)
  186.                                 (setq *step-count* cmd*)
  187.                                 (setq value* (evalhook *sexpr stepper nil)) )
  188.                           (t (step-huh?)) ) ) ) ) )
  189.                
  190.  
  191.  
  192. (defun step-getcmd ()
  193.  
  194. ; Since XLISP normally prompts '>' when asking for input, we add another
  195. ; '>' here to distinguish a stepper prompt. ie stepper prompts >>
  196.  
  197.     (princ " >")
  198.     (read))
  199.  
  200. (defun step-prompt (*prompt *sexpr)
  201.  
  202. ; Here we print the *sexpr with a informative leading character (usually
  203. ; either ? or = ). If the *sexpr is long then we won't print the whole thing
  204. ; just an outline which abbreviates nested lists as (...)
  205.  
  206.    (spaces *step-indent*)
  207.    (princ *prompt)
  208.  
  209.    (let ((len (flatc *sexpr)))
  210.             (cond ((<= (- len *step-indent*) 75)
  211.                         (princ *sexpr) )
  212.                   (t (short-princ *sexpr)) ) )
  213.    *sexpr ) 
  214.  
  215.  
  216. (defun step-help ()
  217.  
  218.     (princ "Here is a summary of the available commands:\n")
  219.     (princ "      s   - steps once more\n")
  220.     (princ "      ?   - prints this help\n")
  221.     (princ "      b   - enter a break loop\n")
  222.     (princ "      c   - continue program until next breakpoint\n")
  223.     (princ "      e   - exit program, return to toplevel\n")
  224.     (princ "      g   - go on without further stepping interruptions\n")
  225.     (princ "      h   - prints this help\n")
  226.     (princ "      n   - continue stepping, but no deeper\n")
  227.     (princ "      q   - quit program, clear breakpoints, return to toplevel\n")
  228.     (princ "      x   - exit, same as e\n")
  229.     (princ "      #   - make # steps at once\n")
  230.     (princ " + <atom> - add this atom to list of breakpoints\n")
  231.     (princ " - <atom> - remove this atom from list of breakpoints\n" ) )
  232.  
  233.  
  234. (defun step-huh? ()
  235.     (princ "Huh?  Type h or ? for help ") )
  236.  
  237.  
  238. ;+
  239. ; The End.
  240. ;-
  241.  
  242.         
  243.   
  244.                
  245.  
  246.